<?php
    include_once('../../src/classes/class.mysql.php');
    
    session_start();
    
    $comtec_id_mainteiner = $_GET["id"];
    
    $db = new MySQL();
    
    $tsql = "SELECT comtec_id_owner, cod_owner, company_name, rut,CONCAT_WS(' ',contact_name,contact_lastname1,contact_lastname2) as contacto,email,phone,contact_position";  
    $tsql .= " FROM owner WHERE comtec_id_mainteiner=$comtec_id_mainteiner and status_reg=1 ORDER BY company_name ASC";
    
    $stmt = $db->query($tsql);       
    
    $texto  = "<table class='table'>";
    if($_SESSION["users"]=="managers"){      
     $texto .= "<tr><th colspan=2></th>";
    }elseif ($_SESSION["users"]!="clients" && $_SESSION["users"]!="technicians") {
     $texto .= "<tr><th></th>";  
    }          
    $texto .= "<th>Codigo</th>
              <th>Nombre</th>
              <th>RUT</th>
              <th>Contacto</th>
              <th>Cargo contacto</th>
              <th>Correo electr&oacute;nico</th>
              <th>Tel&eacute;fono</th>
              </tr>";  
    $cont = 0; 
    while ($row = mysql_fetch_array($stmt, MYSQL_ASSOC)){
     $cont += 1;
     $comtec_id_owner=$row['comtec_id_owner'];   
     $cod_owner=$row['cod_owner'];
     $company_name=$row['company_name'];
     $rut=$row['rut'];  
     $rut_cod = substr($rut, -1, 1);
     $rut = substr($rut,0,strlen($rut)-1);
     $contacto=$row['contacto'];
     $position=$row['contact_position'];
     $email=$row['email'];
     $phone=$row['phone'];
     $texto .= "<tr>";
     if($_SESSION["users"]!="clients" && $_SESSION["users"]!="technicians"){
      $url_edit='http://'.$_SERVER['HTTP_HOST'].'/iconos/edit.png';
      $texto .= "<td><a href='javascript:loadOwner(".$comtec_id_owner.");'><img src='$url_edit' alt='editar' style='border: 0px;' /></a></td>";
     }
     if($_SESSION["users"]=="managers"){
      $url_delete='http://'.$_SERVER['HTTP_HOST'].'/iconos/delete.png';
      $texto .= "<td><a href='javascript:deleteOwner(".$comtec_id_owner.");'><img src='$url_delete' alt='eliminar' style='border: 0px;' /></a></td>";
     }
     $texto .= "<td><a href='javascript:owner(".$comtec_id_owner.");'>$cod_owner</a></td>";
     $texto .= "<td>$company_name</td>";
     $texto .= "<td>".$rut."-".$rut_cod."</td>";
     $texto .= "<td>$contacto</td>";
     $texto .= "<td>$position</td>";
     $texto .= "<td>$email</td>";
     $texto .= "<td>$phone</td>";
     $texto .= "</tr>";
    }
    $texto .= "</table>";
    $texto .= '<div id="result"></div>';
    echo "<p class='total'>Total: $cont</p>".$texto;
?>
